<?php
/**
 *
 * Author: Lyu
 * Date: 2023/7/25
 * Time: 15:06
 */

namespace App\OpenApi\AdminApi\Admin;

use App\Service\Core\Admin\Role\AdminUserRoleListService;
use App\Service\Core\Admin\Role\AdminUserRoleService;
use App\Service\Core\Admin\Role\AdminUserRoleStoreService;
use App\Service\OpenApi\AdminApi\OpenBaseApi;

class AdminUserRoleApi extends OpenBaseApi
{
    public function index(): array
    {
        $list_res = (new AdminUserRoleListService())
            ->setName($this->input('name'))
            ->setStatus($this->input('status'))
            ->setCreatedAtBegin($this->input('created_at_begin'))
            ->setCreatedAtEnd($this->input('created_at_end'))
            ->setFields(['admin_user_role.*', 'allow_edit', 'status_name'])
            ->setPage($this->input('page', 1), $this->input('pageSize', $this->page_size))
            ->getList();
        return alert_info(0, 'ok', $list_res);
    }

    public function store(): array
    {
        return (new AdminUserRoleStoreService())
            ->setName($this->input('name'))
            ->setStatus($this->input('status'))
            ->setSortOrder($this->input('sort_order'))
            ->setRemark($this->input('remark'))
            ->setOperate($this->operate_id, $this->operate_by)
            ->store($this->input('role_id'));
    }

    public function changeStatus(): array
    {
        return AdminUserRoleService::getInstance()->changeStatus($this->input('role_id'), $this->input('status'), $this->operate_id, $this->operate_by);
    }

    public function deleteRole()
    {
        return AdminUserRoleService::getInstance()->deleteRole($this->input('role_id'), $this->operate_id, $this->operate_by);
    }
}
